package com.yunjian.demo.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import top.link.wing.sdk.annotation.AmmApiCheck;
import top.link.wing.sdk.business.LhzhReportService;
import top.link.wing.sdk.dto.RequestVO;
import top.link.wing.sdk.dto.ThirdReportInfoDTO;
import top.link.wing.sdk.dto.TimeQueryVO;
import top.link.wing.sdk.utils.FileUtil;
import top.link.wing.sdk.utils.HttpRequestUtil;
import top.link.wing.sdk.utils.LocalDateTimeUtils;

import java.io.File;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;

/**
 * @Author: chengfangjian
 * @Date: 2023/12/11
 */
@RestController
@RequestMapping("/lhzh/api")
public class AmmController {
    private Logger logger = LoggerFactory.getLogger(AmmController .class);

    private LhzhReportService reportService;

    public AmmController(LhzhReportService reportService) {
        this.reportService = reportService;
    }

    /**
     * 接收推送过来的报告
     * */
    @PostMapping("/report/push")
    @AmmApiCheck
    public Object reportPush(@RequestBody RequestVO vo) throws JsonProcessingException {
        List<ThirdReportInfoDTO> list = HttpRequestUtil.objectMapper.readValue(vo.getData(), new TypeReference<List<ThirdReportInfoDTO>>(){});
        logger.error(HttpRequestUtil.objectMapper.writeValueAsString(list));
        // TODO 处理业务逻辑
//        list.stream().forEach(d -> {
//            File file = FileUtil.downloadFile(d.getFileUrl(), d.getReportName());
//        });
        return true;
    }

    /**
     * 主动获取报告
     * */
    @GetMapping("/report/getReport")
    public  List<ThirdReportInfoDTO> getReport(TimeQueryVO queryVO) throws JsonProcessingException {
        List<ThirdReportInfoDTO> report = reportService.getReport(queryVO);
        logger.error(HttpRequestUtil.objectMapper.writeValueAsString(report));
        // TODO 处理业务逻辑
//        report.stream().forEach(d -> {
//            File file = FileUtil.downloadFile(d.getFileUrl(), d.getReportName());
//        });
        return report;
    }

}
